//
//  UIBarButtonItem+Extensions.swift
//  Weibo
//
//  Created by 李磊 on 2017/6/8.
//  Copyright © 2017年 李磊www. All rights reserved.
//

import Foundation


extension UIBarButtonItem {
    
    /// 自定义barButtionItem
    ///
    /// - Parameters:
    ///   - title: title
    ///   - fontSize: 文字大小 默认16
    ///   - isBack: 是否是返回按钮  如果是加上箭头
    convenience init (title: String, fontSize: CGFloat = 16, target:AnyObject?, action:Selector ,isBack: Bool = false) {
        //Swift 调用OC放回instancetype 返回的是可选类型  可以通过指定类型避免解包
        let btn: UIButton = UIButton.cz_textButton(title, fontSize: fontSize, normalColor: UIColor.darkGray, highlightedColor: UIColor.orange)
        if isBack {
            
            btn.setImage(#imageLiteral(resourceName: "navigationbar_back_withtext"), for: .normal)
            btn.setImage(#imageLiteral(resourceName: "navigationbar_back_withtext_highlighted"), for: .highlighted)
            btn.sizeToFit()

        }
        btn.addTarget(target, action: action, for: .touchUpInside)
        // 调用self
        self.init(customView: btn)
    
    }

    
}
